package http;
import java.io.ByteArrayOutputStream;  
import java.io.IOException;  
import java.io.InputStream;  
import java.net.URL;  
import java.net.URLConnection;  
  
public class UseUrl {  
  
    public static void main(String args[]) throws IOException {  
        long start = System.currentTimeMillis();
        URL url = new URL("http://www.baidu.com");  
        URLConnection conn = url.openConnection();  
        InputStream is = conn.getInputStream();  
        ByteArrayOutputStream out = new ByteArrayOutputStream();  
        byte[] b = new byte[1024];  
        int len = 0;  
        while ((len = is.read(b)) != -1) {  
            out.write(b, 0, len);  
        }  
        String result = out.toString("UTF-8");  
        out.close();  
        is.close();  
        System.out.println(result);
        System.out.println("耗时毫秒数："+(System.currentTimeMillis()-start));
    }  
  
}